package com.example.mobile2121606110syc0331homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textbt;
    private Button bcz;
    private TextView textd1;
    private RadioGroup radioGroup1;
    private RadioButton radio1A;
    private RadioButton radio1B;
    private RadioButton radio1C;
    private RadioButton radio1D;
    private TextView textd2;
    private RadioGroup radioGroup2;
    private RadioButton radio2A;
    private RadioButton radio2B;
    private RadioButton radio2C;
    private RadioButton radio2D;
    private TextView textd3;
    private RadioGroup radioGroup3;
    private RadioButton radio3A;
    private RadioButton radio3B;
    private RadioButton radio3C;
    private RadioButton radio3D;
    private TextView textd4;
    private RadioGroup radioGroup4;
    private RadioButton radio4A;
    private RadioButton radio4B;
    private RadioButton radio4C;
    private RadioButton radio4D;
    private TextView textjg;
    private Button btj;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                radioButton.getText().toString();
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                radioButton.getText().toString();
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        radioGroup3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                radioButton.getText().toString();
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        radioGroup4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                radioButton.getText().toString();
                Log.i("RadioButton ", radioButton.getText().toString());
            }
        });
        btj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int A=radioGroup1.getCheckedRadioButtonId();
                int B=radioGroup2.getCheckedRadioButtonId();
                int C=radioGroup3.getCheckedRadioButtonId();
                int D=radioGroup4.getCheckedRadioButtonId();
                if (A==R.id.radio1A & B==R.id.radio2C & C==R.id.radio3B & D==R.id.radio4A){
                    textjg.setText("分数：100分");
                }else if (A==R.id.radio1A & B==R.id.radio2C & C==R.id.radio3B||B==R.id.radio2C & C==R.id.radio3B & D==R.id.radio4A||A==R.id.radio1A & C==R.id.radio3B & D==R.id.radio4A){
                    textjg.setText("分数：75分");
                }else if (A==R.id.radio1A & B==R.id.radio2C||A==R.id.radio3B & C==R.id.radio3B||A==R.id.radio1A & D==R.id.radio4A||B==R.id.radio2C & C==R.id.radio3B||B==R.id.radio2C & D==R.id.radio4A||C==R.id.radio3B & D==R.id.radio4A){
                    textjg.setText("分数：50分");
                }else if (A==R.id.radio1A||B==R.id.radio2C||C==R.id.radio3B||D==R.id.radio4A){
                    textjg.setText("分数：25分");
                }else if (A==-1||B==-1||C==-1||D==-1) {
                    Toast.makeText(MainActivity.this, "未完成", Toast.LENGTH_SHORT).show();
                }else{
                    textjg.setText("分数：0分");
                }
            }
        });
        bcz.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                radio1A.setChecked(false);
                radio1B.setChecked(false);
                radio1C.setChecked(false);
                radio1D.setChecked(false);
                radio2A.setChecked(false);
                radio2B.setChecked(false);
                radio2C.setChecked(false);
                radio2D.setChecked(false);
                radio3A.setChecked(false);
                radio3B.setChecked(false);
                radio3C.setChecked(false);
                radio3D.setChecked(false);
                radio4A.setChecked(false);
                radio4B.setChecked(false);
                radio4C.setChecked(false);
                radio4D.setChecked(false);
                textjg.setText("");
                Toast.makeText(MainActivity.this,"已重置",Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        textbt = (TextView) findViewById(R.id.textbt);
        bcz = (Button) findViewById(R.id.bcz);
        textd1 = (TextView) findViewById(R.id.textd1);
        radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
        radio1A = (RadioButton) findViewById(R.id.radio1A);
        radio1B = (RadioButton) findViewById(R.id.radio1B);
        radio1C = (RadioButton) findViewById(R.id.radio1C);
        radio1D = (RadioButton) findViewById(R.id.radio1D);
        textd2 = (TextView) findViewById(R.id.textd2);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        radio2A = (RadioButton) findViewById(R.id.radio2A);
        radio2B = (RadioButton) findViewById(R.id.radio2B);
        radio2C = (RadioButton) findViewById(R.id.radio2C);
        radio2D = (RadioButton) findViewById(R.id.radio2D);
        textd3 = (TextView) findViewById(R.id.textd3);
        radioGroup3 = (RadioGroup) findViewById(R.id.radioGroup3);
        radio3A = (RadioButton) findViewById(R.id.radio3A);
        radio3B = (RadioButton) findViewById(R.id.radio3B);
        radio3C = (RadioButton) findViewById(R.id.radio3C);
        radio3D = (RadioButton) findViewById(R.id.radio3D);
        textd4 = (TextView) findViewById(R.id.textd4);
        radioGroup4 = (RadioGroup) findViewById(R.id.radioGroup4);
        radio4A = (RadioButton) findViewById(R.id.radio4A);
        radio4B = (RadioButton) findViewById(R.id.radio4B);
        radio4C = (RadioButton) findViewById(R.id.radio4C);
        radio4D = (RadioButton) findViewById(R.id.radio4D);
        textjg = (TextView) findViewById(R.id.textjg);
        btj = (Button) findViewById(R.id.btj);
    }
}